package com.wangyh.edit.prettyedit.pages;

import com.wangyh.edit.prettyedit.constant.EditConstant;
import com.wangyh.edit.prettyedit.help.PropertyPage;
import com.wangyh.edit.prettyedit.help.VersionPage;
import com.wangyh.edit.prettyedit.html.EditHtmlPage;
import com.wangyh.edit.prettyedit.txt.TextCodePage;
import com.wangyh.edit.prettyedit.welcome.WelcomePage;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;

/**
 * 页面创建工厂
 * @author wangyh
 *
 */
public class PageFactory {

    public static IPageService createPageService(String itemName) {
        setMenu();

        IPageService pageService = null;
        switch(itemName) {
            case "version":
                //版本界面
                pageService = new VersionPage();
                break;
            case "welcome":
                //欢迎界面
                pageService = new WelcomePage();
                break;
            case "about":
                //关于我们
                pageService = new AboutPage();
                break;
            case "fileDesc":
                //文件简介
                pageService = new FileDescPage();
                break;
            case "txt":
                //纯文本
                pageService = new TextCodePage(EditConstant.mainFrameView);
                break;
            case "markdown":
                //markdown 格式
                pageService = new MarkdownFramePage(EditConstant.mainFrameView);
                break;
            case "markdownCode":
                //markdown编辑区
                pageService = new MarkdownCodePage();
                break;
            case "flow":
                //流程编辑区
                pageService = new FlowPage();
                break;
            case "html":
                //html富文本
                pageService = new EditHtmlPage();
                break;
            case "properties":
                //系统配置列表
                pageService = new PropertyPage();
                break;
            case "fileList":
                //系统配置列表
                pageService = new FileListPage();
                break;
            default:
                //默认版本界面
                pageService = new VersionPage();
                break;
        }
        return pageService;
    }

    /**
     * 初始化菜单，哪些是禁用的
     */
    private static void setMenu(){
        //获取菜单
        MenuBar menuBar = (MenuBar) EditConstant.mainFrameView.getSceneRoot().getTop();
        if(menuBar == null){
            return;
        }
        //保存
        Menu menu = menuBar.getMenus().get(1);
        MenuItem saveMenu = menu.getItems().get(0);
        saveMenu.setDisable(true);

        MenuItem menuItem1 = menu.getItems().get(1);
        menuItem1.setDisable(true);

        MenuItem menuItem2 = menu.getItems().get(2);
        menuItem2.setDisable(true);

        MenuItem menuItem3 = menu.getItems().get(3);
        menuItem3.setDisable(true);

        //编辑
        Menu editMenu = menuBar.getMenus().get(2);
        //大字体
        MenuItem big = editMenu.getItems().get(0);
        big.setDisable(true);
        //小字体
        MenuItem small = editMenu.getItems().get(1);
        small.setDisable(true);
        //恢复默认
        MenuItem re = editMenu.getItems().get(2);
        re.setDisable(true);
    }
}
